package cn.ikun.wy.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppJdbcSelect {
    public static void main(String[] args) throws Exception {
        // 1. 加载驱动类
        Class.forName("com.mysql.jdbc.Driver");
        // 2. 获取连接
        String url = "jdbc:mysql://localhost:3306/wy666?useSSL=false";
        String username = "root";
        String password = "wy2wxyan";
        Connection connection = DriverManager.getConnection(url, username, password);
        // 3. 创建陈述句对象
        Statement statement = connection.createStatement();
        // 4. 执行查询
        String sql = "SELECT id, username FROM `wy`";
        ResultSet set = statement.executeQuery(sql);
        // 5. 获取数据
        // +----+----------+
        // | id | username |
        // +----+----------+
        // |  1 | Jenkins  | ←--
        // |  2 | timor    |
        // +----+----------+
        set.next();
        // the first column is 1, the second is 2
        String string = set.getString(2);
        System.out.println(string);
    }

}
